package com.santu.edu.supporter.biz.order.kd.pojo.dto;

import cn.hutool.core.collection.CollUtil;
import com.santu.edu.supporter.biz.user.pojo.dto.UserAddressDTO;
import com.santu.edu.supporter.util.PageData;
import lombok.Data;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author luoyaoqi
 * @createTime 2024/3/7
 * @description
 */
@Data
@Accessors(chain = true)
public class KdOrderInfoDTO {

    /**
     * 订单号
     */
    private String orderId;

    /**
     * 快递点id
     */
    private BuildingsInfo buildingsInfo;

    /**
     * 购买的商品信息
     */
    private String goodInfo;

    /**
     * 商品图片地址
     */
    private String imageUrl;

    /**
     * 商品类型[0:小件,1:中件,3:大件]
     */
    private Integer goodType;

    /**
     * 价钱
     */
    private BigDecimal price;

    /**
     * 备注信息
     */
    private String remarkInfo;

    /**
     * 送货地址id
     */
    private AddressInfo addressInfo;

    /**
     * 订单状态
     */
    private Integer orderType;

    /**
     * 货物状态
     */
    private Integer processType;

    /**
     * 送达照片
     */
    private String sendGoodImage;



    @Data
    public static class BuildingsInfo {

        /**
         * 楼栋id
         */
        private String buildingsId;

        /**
         * 楼栋地址
         */
        private String buildingsName;
    }

    @Data
    public static class AddressInfo {
        /**
         * 地址id
         */
        private BuildingsInfo buildingsInfo;

        /**
         * 详细地址
         */
        private String addressInfo;

        /**
         * 收件人姓名
         */
        private String userName;

        /**
         * 收件人电话
         */
        private String phone;
    }


    public static KdOrderInfoDTO createItem(KdOrderDTO dto) {
        return new KdOrderInfoDTO()
                .setOrderId(dto.getOrderId())
                .setGoodInfo(dto.getGoodInfo())
                .setImageUrl(dto.getImageUrl())
                .setGoodType(dto.getGoodType().getCode())
                .setPrice(dto.getPrice())
                .setRemarkInfo(dto.getRemarkInfo())
                .setOrderType(dto.getOrderType().getCode())
                .setProcessType(dto.getProcessType().getCode())
                .setSendGoodImage(dto.getSendGoodImage());
    }


    public void setBuildingsInfo(String buildingsId,String buildingsName) {
        BuildingsInfo item = new BuildingsInfo();
        item.setBuildingsId(buildingsId);
        item.setBuildingsName(buildingsName);
        this.setBuildingsInfo(item);
    }

    public void setAddressInfo(UserAddressDTO userAddressDTO, String buildingsName) {
        AddressInfo item = new AddressInfo();
        item.setAddressInfo(userAddressDTO.getAddressInfo());
        item.setUserName(userAddressDTO.getUserName());
        item.setPhone(userAddressDTO.getPhone());
        BuildingsInfo buildingsInfo = new BuildingsInfo();
        buildingsInfo.setBuildingsId(userAddressDTO.getBuildingsId());
        buildingsInfo.setBuildingsName(buildingsName);
        item.setBuildingsInfo(buildingsInfo);
        this.setAddressInfo(item);
    }
}
